﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;

namespace Meraz.Core.Repositories
{
    public class AliasRepository : EFRepositoryBase<Alias, int>, IAliasRepository
    {
        public AliasRepository() : base() { }
        public AliasRepository(Data.IMerazContext context) : base(context) { }
        public override Alias GetById(int id)
        {
            return context.Aliases
                .Where(where1 => where1.ID == id)
                .FirstOrDefault();
        }
        public List<Alias> GetBlogAliases(string blogName)
        {
            return context.Aliases
                .Where(where1 => where1.BlogName == blogName)
                .ToList();
        }

        public Alias GetByName(string blogName, string name)
        {
            return context.Aliases
                .Where(where1 => where1.BlogName == blogName && where1.Name == name)
                .FirstOrDefault();
        }

        public override void Add(Alias entity)
        {
            context.Aliases.AddObject(entity);
        }

        public override void Delete(Alias entity)
        {
            context.Aliases.DeleteObject(entity);
        }

        public override List<Alias> All()
        {
            return context.Aliases.ToList();
        }
    }
}
